package com.spzx.product.service.impl;

import com.spzx.product.service.TestService;
import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2025/3/4 18:56
 * @注释
 */
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void testLock() {
        //查询Redis中的num值
        String value = this.stringRedisTemplate.opsForValue().get("num");
        //没有该值return
        if(StringUtils.isBlank(value)){
            return ;
        }
        //有值就转换成int
        int num = Integer.parseInt(value);
        this.stringRedisTemplate.opsForValue().set("num", String.valueOf(++num));
    }
}
